<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="top.shiyiri.pojo.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 14533
  Date: 2022/1/30
  Time: 16:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        table{
            width: 500px;
            border-collapse: collapse;
            border: 1px black solid;
        }
        th,td {
            border: 1px black solid;
            text-align: center;
        }
    </style>
</head>
<body>
    <%--
        遍历1到10，输出
        begin属性设置开始的索引
        end属性设置结束的索引
        var属性表示循环的变量
        step表示步长
    --%>
    <table border="1">
        <c:forEach begin="1" end="10" var="i" step="1">
            <tr>
                <td>第${i}行</td>
            </tr>
        </c:forEach>
    </table>
    <hr/>
    <%--
    遍历Object数组
    items表示遍历的数据源
    var表示当前遍历到的数据
    --%>
    <%
        request.setAttribute("arr", new String[]{"63242349237", "749317429347329", "132749324223"});
    %>
    <c:forEach items="${arr}" var="item">
        ${item} <br/>
    </c:forEach>
    <hr/>

    <%
        Map<String, String> map = new HashMap<>();
        map.put("key1", "value1");
        map.put("key2", "value2");
        map.put("key3", "value3");
        request.setAttribute("maps", map);
    %>
    <c:forEach items="${maps}" var="entry">
        ${entry.key} = ${entry.value}<br/>
    </c:forEach>
    <hr/>

    <%
        List<Student> studentList = new ArrayList<>();
        for (int i = 1; i < 11; i++) {
            studentList.add(new Student(i, "username"+i, "password_"+i, 10+i, "234323423"+i));
        }
        request.setAttribute("stus", studentList);
    %>
    <table>
        <tr>
            <th>编号</th>
            <th>用户名</th>
            <th>密码</th>
            <th>年龄</th>
            <th>电话</th>
            <th>操作</th>
        </tr>
        <%--
            items表示遍历的集合
            var表示遍历到的数据
            begin表示遍历的开始索引值
            end表示结果的索引值
        --%>
        <c:forEach begin="2" end="7" varStatus="status" items="${stus}" var="stu">
            <tr>
                <td>${stu.id}</td>
                <td>${stu.username}</td>
                <td>${stu.password}</td>
                <td>${stu.age}</td>
                <td>${stu.phone}</td>
                <td>
                    ${status.end}
<%--                    <a href="#">修改</a>--%>
<%--                    <a href="#">删除</a>--%>
                </td>
            </tr>
        </c:forEach>

    </table>
</body>
</html>
